package kr.co.redcircle.broker.io;

import java.util.HashMap;

import kr.co.redcircle.broker.Broker;
import net.sf.json.JSONObject;

public class BrokerRequest extends HashMap<String, Object> implements IDefaultIO {
	/**

	 */
	private static final long serialVersionUID = 3215803124039919731L;
	public static final String PARAMETERS = "parameters";
	
	private String host;
	private int port;

	public BrokerRequest(){
		
	}

	public BrokerRequest(String from, String to, String business, String method){
		this.put(Broker.FROM, from);
		this.put(Broker.TO, to);
		this.put(Broker.BUSINESS_S, business);
		this.put(Broker.METHOD, method);
	}
	
	public void setFrom(String value){
		this.put(Broker.FROM, value);
	}

	public void setTo(String value){
		this.put(Broker.TO, value);
	}

	public void setBusiness(String value){
		this.put(Broker.BUSINESS_S, value);
	}

	public void setMethod(String value){
		this.put(Broker.METHOD, value);
	}

	public void setParameters(Object value){
		this.put(Broker.PARAMETERS, value);
	}

	public String getFrom(){
		return (String)this.get(Broker.FROM);
	}

	public String getTo(){
		return (String)this.get(Broker.TO);
	}

	public String getBusiness(String value){
		return (String)this.get(Broker.BUSINESS_S);
	}

	public String getMethod(String value){
		return (String) this.get(Broker.METHOD);
	}

	public Object getParameters(Object value){
		return this.get(Broker.PARAMETERS);
	}
	public void setServer(String host, int port) {
		this.put(Broker.HOST, host);
		this.put(Broker.PORT, port);
	}

	public String getHost() {
		return (String) this.get(Broker.HOST);
	}

	public int getPort() {
		return (Integer) this.get(Broker.HOST);
	}

	@Override
	public String getHandler() {
		return get(Broker.TO) + "." + get(Broker.BUSINESS_S) + "." + get(Broker.METHOD);
	}

	@Override
	public String toString() {
		return JSONObject.fromObject(this).toString();
	}
}
